package cn.com.dhc.danlu.widget;

import android.content.Context;
import android.support.v7.widget.AppCompatEditText;
import android.util.AttributeSet;

/**
 * author: 李一方(<a href="mailto:liyifang@danlu.com">liyifang@danlu.com</a>)<br/>
 * version: 1.0.0<br/>
 * since: 2017-03-30 16:33
 *
 * <p>
 * 光标时始终置后的 EditText
 * </p>
 */
public class CursorEndEdittext extends AppCompatEditText {
    public CursorEndEdittext(Context context) {
        super(context);
    }

    public CursorEndEdittext(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void onSelectionChanged(int start, int end) {
        CharSequence text = getText();
        if (text != null) {
            if (start != text.length() || end != text.length()) {
                setSelection(text.length(), text.length());
                return;
            }
        }
        super.onSelectionChanged(start, end);
    }
}
